﻿using System;
using System.Diagnostics;
using iTunesLib;

namespace Sensors
{
    class iTunesSensor
    {
        
        public void run2()
        {
            iTunesApp app = new iTunesAppClass();
            app.OnPlayerPlayEvent += new _IiTunesEvents_OnPlayerPlayEventEventHandler(app_OnPlayerPlayEvent);
            //Console.ReadLine();
            //while (true) { }
        }
        private void app_OnPlayerPlayEvent(object iTrack)
        {
            Console.WriteLine("TRACK CHANGED");
        }
        

        /*
        public void run()
        {
            bool iTunesOpen = false;
            //Searches to make sure iTunes is included in the list of running process,
            //could possibly interface with ProcessSensor
            Process[] proc = System.Diagnostics.Process.GetProcesses(Environment.MachineName);
            foreach (Process p in proc)
            {
                if (p.ProcessName.ToString().Equals("iTunes"))
                {
                    iTunesOpen = true;
                    break;
                }
            }

            //Gives song data if open
            if (iTunesOpen)
            {
                Console.WriteLine("iTunes is open.");
                iTunesApp app = new iTunesAppClass();
                if (app.CurrentTrack != null)
                {
                    Console.WriteLine("Current Song: {0}", app.CurrentTrack.Name.ToString());
                    Console.WriteLine("Current Artist: {0}", app.CurrentTrack.Artist.ToString());
                    Console.WriteLine("Current State : {0}", app.PlayerState.ToString());
                }
                else
                    Console.WriteLine("No track Currently Playing");
                
                if (app.CurrentPlaylist != null)
                Console.WriteLine("Current Playlist: {0}", app.CurrentPlaylist.Name.ToString());
            }
            else 
            {
                Console.WriteLine("iTunes is not open.");
            }
        }*/
    }
}
